/**
 * 
 */
package com.htht.smartschool.action.bigexam;

import java.util.List;
import java.util.Map;

import com.google.gson.reflect.TypeToken;
import com.htht.smartschool.action.baseaction.BaseAction;
import com.htht.smartschool.common.model.ParamData;
import com.htht.smartschool.common.servlet.DataContainer;
import com.htht.smartschool.model.bigexam.BigExamBean;
import com.htht.smartschool.model.bigexam.SmallTestBean;
import com.htht.smartschool.model.card.TPhonebook;
import com.htht.smartschool.model.student.TStudent;
import com.htht.smartschool.service.bigexam.BigExamService;
import com.htht.smartschool.util.system.GsonUtils;

/**
 * @author wuqiwei
 *
 */
public class BigExamAction extends BaseAction {

	@Override
	public boolean processData(DataContainer obj, ParamData pd) {
		BigExamService bigexamService = new BigExamService();
		boolean flag = false;
		BigExamBean big =null;
		SmallTestBean small =  null;
		try {
			big = (BigExamBean) GsonUtils.getInstance().fromJson(pd.getData(), BigExamBean.class);
			small =(SmallTestBean) GsonUtils.getInstance().fromJson(pd.getData(), SmallTestBean.class);
		} catch (Exception e) {
			
		}
		if(pd.getCmd().equalsIgnoreCase("getExamTotalList")){//获取考试总榜
			Map map = bigexamService.getExamTotalList(big);
			if(map != null){
				flag = true;
				obj.setData(map);
			}else{
				obj.setData("查询失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("addBigExamInfo")){//添加考试
			List<BigExamBean> biglist = GsonUtils.getInstance().gson.fromJson(pd.getData(),  new TypeToken<List<BigExamBean>>(){}.getType());
			Map result = bigexamService.addBigExamInfo(biglist);
			String examcode =  (String) result.get("examcode");
			bigexamService.addResult(biglist,examcode);//批量添加学生
			if(result != null){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("添加失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("getAllExamInfo")){//获取年级全部考试信息
			Map map = bigexamService.getAllExamInfo(big);
			if(map != null){
				flag = true;
				obj.setData(map);
			}else{
				obj.setData("查询失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("getExamDetial")){//获取考试详情
			List<BigExamBean> result = bigexamService.getExamDetial(big);
			if(result.size() > 0){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("查询失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("UpdateExamInfo")){//编辑考试信息
			List<BigExamBean> biglist = GsonUtils.getInstance().gson.fromJson(pd.getData(),  new TypeToken<List<BigExamBean>>(){}.getType());
			boolean result = bigexamService.UpdateExamInfo(biglist);
			if(result){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("添加失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("deleteExamInfo")){//删除考试
			boolean result = bigexamService.deleteExamInfo(big);
			if(result){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("添加失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("getOneExamInfo")){//查看每次考试的详细信息
			List<BigExamBean> result = bigexamService.getOneExamInfo(big);
			if(result.size() > 0){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("查询失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("getEveryExamInfo")){//查看每科考试学生成绩的信息
			Map result = bigexamService.getEveryExamInfo(big);
			if(result != null){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("查询失败！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("deleteSubjectExamInfo")){//删除考试科目信息
			boolean result = bigexamService.deleteSubjectExamInfo(big);
			if(result){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("删除失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("getParentChildrenExamList")){//获取家长端孩子考试列表
			List<BigExamBean> result = bigexamService.getParentChildrenExamList(big);
			if(result.size() > 0){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("查询失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("getParentChildrenOneEXamResult")){//获取家长端一科成绩成绩单详情
			List<BigExamBean> result = bigexamService.getParentChildrenOneEXamResult(big);
			if(result.size() > 0){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("查询失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("getParentChildrenOneExamRank")){//获取家长端一次考试孩子的成绩单
			List<BigExamBean> result = bigexamService.getParentChildrenOneExamRank(big);
			if(result.size() > 0){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("查询失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("getTeahcerAllExamInfo")){//获取教师端考试列表
			Map map = bigexamService.getTeahcerAllExamInfo(big);
			if(map != null){
				flag = true;
				obj.setData(map);
			}else{
				obj.setData("查询失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("getTeahcerAllStudent")){//查询教师端学生信息
			Map map = bigexamService.getTeahcerAllStudent(big);
			if(map != null){
				flag = true;
				obj.setData(map);
			}else{
				obj.setData("查询失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("getTeacherTestList")){//获取教师端小测考试列表
			Map map = bigexamService.getTeacherTestList(small);
			if(map != null){
				flag = true;
				obj.setData(map);
			}else{
				obj.setData("查询失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("insertTeacherSmallEaxmInfo")){//添加教师端小测考试信息
			boolean result = bigexamService.insertTeacherSmallEaxmInfo(small);
			if(result){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("添加失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("teacherEntryResult")){//教师端录入成绩
			List<SmallTestBean> smalllist = GsonUtils.getInstance().gson.fromJson(pd.getData(),  new TypeToken<List<SmallTestBean>>(){}.getType());
			boolean result= bigexamService.teacherEntryResult(smalllist);
			if(result){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("添加失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("queryTeacherStudent")){//获取教师端班级小测学生列表
			Map map = bigexamService.queryTeacherStudent(small);
			if(map != null){
				flag = true;
				obj.setData(map);
			}else{
				obj.setData("查询失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("updateTeahcerExamInfo")){//修改教师端考试信息
			boolean result = bigexamService.updateTeahcerExamInfo(small);
			if(result){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("修改失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("deleteTeacherExamInfo")){//删除教师端考试信息
			boolean result = bigexamService.deleteTeacherExamInfo(small);
			if(result){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("删除失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("getTeacherResultList")){//获取教师端成绩列表
			Map map = bigexamService.getTeacherResultList(small);
			if(map != null){
				flag = true;
				obj.setData(map);
			}else{
				obj.setData("查询失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("teacherEntryResultInfo")){//教师端添加校考成绩
			List<SmallTestBean> smalllist = GsonUtils.getInstance().gson.fromJson(pd.getData(),  new TypeToken<List<SmallTestBean>>(){}.getType());
			boolean result = bigexamService.teacherEntryResultInfo(smalllist);
			if(result){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("删除失败");
			}
		}
		return flag;
	}

}
